﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using Common.Logging;
using Quartz;
using Quartz.Impl;

namespace Jackie.Quartz.WindowServiceServer
{
    public partial class QuartzService : ServiceBase
    {
        private ILog logger;
        private IScheduler scheduler;

        public QuartzService()
        {
            InitializeComponent();
            logger = LogManager.GetLogger(GetType());

            logger.Info("Initializing Quartz Service");
            ISchedulerFactory schedulerFactory = new StdSchedulerFactory();
            scheduler = schedulerFactory.GetScheduler();
            logger.Info("Quartz Service Initialized");
        }

        protected override void OnStart(string[] args)
        {
            logger.Info("Starting Quartz Service");
            scheduler.Start();
            logger.Info("Quartz Service Started");
        }

        protected override void OnStop()
        {
            logger.Info("Stopping Quartz Service");
            scheduler.Shutdown(true);
            logger.Info("Quartz Service Stopped");
        }
    }
}
